# app.py
from flask import Flask, request, jsonify, render_template
from __05__bert_predict import predict_fun

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/predict', methods=['POST'])
def predict_api():
    try:
        # 获取请求数据
        data = request.get_json()

        if 'text' not in data:
            return jsonify({'error': '缺少文本内容'}), 400

        # 调用预测函数
        result = predict_fun({'text': data['text']})

        return jsonify(result)

    except Exception as e:
        return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8001, debug=True)
